package vip.finance.makemoney.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import vip.finance.makemoney.apiSpider.eastmoney.EastMoneyTradeApi;
import vip.finance.makemoney.common.WebJson;
import vip.finance.makemoney.service.IUserService;

/**
 * 股票交易
 */
@RestController
@RequestMapping("/trade")
public class TradeController extends BaseController {
    @Resource
    private IUserService userService;
    @Resource
    private EastMoneyTradeApi eastmoneyTradeApi;

    //登录交易账户
    @PostMapping("/login-trade")
    public Object loginTrade(@RequestParam String randNum, @RequestParam String password, @RequestParam String identifyCode) {
        userService.loginTrade(currentUser(), randNum, identifyCode, password);
        return WebJson.success();
    }

    //我的资产
    @GetMapping("/get-assets")
    public Object getAssets(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_assets());
    }

    //我的持仓
    @GetMapping("/get-stock-list")
    public Object getStockList(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_stock_list());
    }

    //提交委托
    @GetMapping("/submit")
    public Object submit(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.submit());
    }

    //撤单
    @GetMapping("/revoke")
    public Object revoke(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.revoke());
    }

    //当日委托
    @GetMapping("/get-orders-data")
    public Object get_orders_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_orders_data());
    }

    //当日成交
    @GetMapping("/get-deal-data")
    public Object get_deal_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_deal_data());
    }

    //登录验证码
    @GetMapping("/YZM")
    public Object yzm(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.yzm());
    }

    //登录验证
    @GetMapping("/authentication-check")
    public Object authentication_check(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.authentication_check());
    }

    //历史成交
    @GetMapping("/get-his-deal-data")
    public Object get_his_deal_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_his_deal_data());
    }

    //历史委托
    @GetMapping("/get-his-orders-data")
    public Object get_his_orders_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_his_orders_data());
    }

    //查询可申购新股列表
    @GetMapping("/get-can-buy-new-stock-list-v3")
    public Object get_can_buy_new_stock_list_v3(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_can_buy_new_stock_list_v3());
    }

    //查询可申购新债列表
    @GetMapping("/get-convertible-bond-list-v2")
    public Object get_convertible_bond_list_v2(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.get_convertible_bond_list_v2());
    }

    //批量申购
    @GetMapping("/submit-bat-trade-v2")
    public Object submit_bat_trade_v2(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.submit_bat_trade_v2());
    }

    //信用我的资产
    @GetMapping("/cr-get-rzrq-asserts")
    public Object cr_get_rzrq_asserts(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_rzrq_asserts());
    }

    //信用我的持仓
    @GetMapping("/cr-query-collateral")
    public Object cr_query_collateral(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_query_collateral());
    }

    //信用提交委托
    @GetMapping("/cr-submit")
    public Object cr_submit(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_submit());
    }

    //信用撤单
    @GetMapping("/cr-revoke")
    public Object cr_revoke(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_revoke());
    }

    //信用当日委托
    @GetMapping("/cr-get-orders-data")
    public Object cr_get_orders_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_orders_data());
    }

    //信用当日成交
    @GetMapping("/cr-get-deal-data")
    public Object cr_get_deal_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_deal_data());
    }

    //信用历史委托
    @GetMapping("/cr-get-his-orders-data")
    public Object cr_get_his_orders_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_his_orders_data());
    }

    //信用历史成交
    @GetMapping("/cr-get-his-deal-data")
    public Object cr_get_his_deal_data(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_his_deal_data());
    }

    //信用查询可申购新股列表
    @GetMapping("/cr-get-can-buy-new-stock-list-v3")
    public Object cr_get_can_buy_new_stock_list_v3(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_can_buy_new_stock_list_v3());
    }

    //信用查询可申购新债列表
    @GetMapping("/cr-get-convertible-bond-list-v2")
    public Object cr_get_convertible_bond_list_v2(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_get_convertible_bond_list_v2());
    }

    //信用批量申购
    @GetMapping("/cr-submit-bat-trade-v2")
    public Object cr_submit_bat_trade_v2(@RequestParam Integer tradeId) {
        currentTradeUserId(tradeId);
        return WebJson.success(eastmoneyTradeApi.cr_submit_bat_trade_v2());
    }
}
